package com.shycloud.mido.organ.test;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

/**
 * @author Xiaoxing Yu
 * @date 2020/6/1
 **/
public class GenerateActivationCode {

	public static void main(String[] args){

		Map hsMap= new HashMap();

		for(int i = 0; i < 100; i++) {
			String xxxx = new GenerateActivationCode().generateGiftCode("2r");

			System.out.println(xxxx);
			hsMap.put(xxxx, xxxx);
		}
		System.out.println(hsMap.size());
	}

	private static String generateGiftCode(String prefix){
		StringBuffer sb = new StringBuffer();
		sb.append(prefix);
		for(int i = 0;i < 10-2; i++){
			Random random = new Random();
			String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num";
			if("char".equalsIgnoreCase(charOrNum)){
				int choice = random.nextInt(2) % 2 == 0 ? 65 : 97;
				char val = (char)(choice + random.nextInt(26));
				sb.append(val);
			}else if("num".equalsIgnoreCase(charOrNum)){
				int num = random.nextInt(9);
				sb.append(num);
			}
		}
		return sb.toString();

	}

}
